/* Copyright Statement:
 *
 * ECARX Technology Limited is the owner of the copyright and the trade secret of this software.
 * Without permission, no one has the right to obtain, disclose or use this software in any way.
 *
 */

#include <thread>
#include <linux/input.h>
#include <optional>
#include <string>

#define KEY_INPUT_NAME    "Sleep Button"

#define KEYCODE_ENTER_STR 142
#define KEYCODE_EXIT_STR 143

namespace android {
namespace hardware {
namespace automotive {
namespace vehicle {
namespace V2_0 {

namespace impl {

    class ECarXInputProvider {
    public:
        using KeyCodeCallback = std::function<void(int keyCode)>;

        ECarXInputProvider();

        int openInput(const char* name);
        void startLoop();
        void stop();
        void readEventThread();
        void registerKeyCodeCallback(KeyCodeCallback&& callback);
        void onKeyDown(int keyCode);

        ~ECarXInputProvider();
    private:
        struct kevent : public ::input_event {
            kevent();
            bool isKeypress() const;
            bool isKeydown() const;
            bool isKeyup() const;
        };
        static_assert(sizeof(kevent) == sizeof(::input_event), "do not add data to input_event");
        int mInputFd;
        KeyCodeCallback mCallback;

    protected:
        std::unique_ptr<std::thread> mReadThread;
    };


}  // impl

}  // namespace V2_0
}  // namespace vehicle
}  // namespace automotive
}  // namespace hardware
}  // namespace android

